package com.ext.aic.handler;

import com.ext.aic.AICManager;
import com.ext.aic.beans.DraftInfo;
import com.ext.aic.beans.DraftInfo_;
import com.eyinfo.storage_objectbox.PageInfo;

public class DraftHandler {
    private static volatile DraftHandler instance;

    public static DraftHandler getInstance() {
        if (instance == null) {
            synchronized (DraftHandler.class) {
                if (instance == null) {
                    instance = new DraftHandler();
                }
            }
        }
        return instance;
    }

    public void saveDraft(DraftInfo draftInfo) {
        AICManager.getInstance().insertOrUpdate(DraftInfo.class, draftInfo);
    }

    public PageInfo<DraftInfo> getDraftList(int page, int size) {
        return AICManager.getInstance().queryPage(DraftInfo.class, page, size, queryBuilder ->
                queryBuilder.orderDesc(DraftInfo_.updateTime)
        );
    }
}
